//
//  TalkBookCoverView.m
//  talkDemo
//
//  Created by telen on 15/4/17.
//  Copyright (c) 2015年 刘赞黄Telen. All rights reserved.
//

#import "TalkBookCoverView.h"

@implementation TalkBookCoverView

+ (TalkBookCoverView *)talkCover:(UIImage *)cover ratio:(CGFloat)ratio_w
{
    CGRect frame = CGRectMake(768/ratio_w, 226/ratio_w, 768/ratio_w, 206/ratio_w);
    return [[self alloc] initWithFrame:frame cover:cover ratio:ratio_w];
}

- (instancetype)initWithFrame:(CGRect)frame cover:(UIImage *)cover ratio:(CGFloat)ratio_w
{
    if (self = [super initWithFrame:frame]) {
        self.ratio = ratio_w;
        //
        UIImage* image = cover;
        if (image) {
            UIImageView* cv = [[UIImageView alloc] initWithFrame:CGRectMake(100/ratio_w, 0, 150/ratio_w, 206/ratio_w)];
            cv.image = image;
            [self addSubview:cv];
        }
        //
        UIImageView* ltv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"talk_text.png"]];
        ltv.center = CGPointMake(316/ratio_w+ltv.frame.size.width*0.5, frame.size.height*0.5);
        [self addSubview:ltv];
    }
    return self;
}

- (void)show
{
    CGRect frame = self.frame;
    frame.origin = CGPointMake(0, frame.origin.y);
    [UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.frame = frame;
    } completion:^(BOOL finished) {
        
    }];
    self.isShown = YES;
}

- (void)unshow
{
    CGRect frame = self.frame;
    frame.origin = CGPointMake(-frame.size.width, frame.origin.y);
    CGRect frame2 = frame;
    frame2.origin = CGPointMake(768/self.ratio, frame.origin.y);
    [UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.frame = frame;
    } completion:^(BOOL finished) {
        self.frame = frame2;
    }];
    
    self.isShown = NO;
}

@end
